<template>
	<view class="page-content">
		<u-loading-page :loading="loading" bg-color="#e8e8e8"></u-loading-page>
		<u-cell-group>
			<u-cell title="设备名称" :value="detailform.deviceName"></u-cell>
			<u-cell title="设备编码" :value="detailform.deviceNum"></u-cell>
			<u-cell title="设备属性" :value="detailform.deviceType"></u-cell>
			<u-cell title="是否网关设备" :value="detailform.isGateway"></u-cell>
			<u-cell title="所属网关编码" :value="detailform.gatewayNum"></u-cell>
			<u-cell title="生产厂商" :value="detailform.manufacturer"></u-cell>
			<u-line color="#2979ff"></u-line>

			<u-cell title="长者姓名" :value="detailform.name"></u-cell>
			<u-cell title="性别" :value="detailform.sex"></u-cell>
			<u-cell title="身份证号码" :value="detailform.idNumber"></u-cell>
			<u-cell title="联系电话" :value="detailform.phone"></u-cell>
			<u-cell title="居住地址" :value="getAddress(detailform)">
			</u-cell>
			<u-cell title="详细地址" :value="getDetailAddress(detailform)"></u-cell>
			<u-cell title="紧急联系人" :value="detailform.emergencyContactName"></u-cell>
			<u-cell title="紧急联系人电话" :value="detailform.emergencyContactPhone"></u-cell>
			<u-line color="#2979ff"></u-line>

			<u-cell title="部署人员" :value="detailform.deployName"></u-cell>
			<u-cell title="登记人员" :value="detailform.registerName"></u-cell>
			<u-cell title="审核人员" :value="detailform.auditorName"></u-cell>
			<u-cell title="入户时间" :value="detailform.deviceDeploy"></u-cell>
			<u-cell title="备注" :value="detailform.notes"></u-cell>

			<!--设备名称 deviceName
					设备编码 deviceNum
					设备属性 deviceType
					是否网关设备 isGateway
					所属网关编码 gatewayNum
					生产厂商 manufacturer
					
					老人姓名 name
					性别 sex 
					身份证号码 idNumber
					联系电话 phone
					province，city，district，town，village，street
					 房屋号 roomNum
					详细地址 residenceAdd
					
			        紧急联系人 emergencyContactName
					紧急联系人电话 emergencyContactPhone
					
					所属养老机构	 institutionName	
					机构社会信用代码	 institutionCode
			
					部署人员 deployName
					登记人员 registerName
					审核人员 auditorName
					入户时间 deviceDeploy
					
					备注 notes-->
		</u-cell-group>
		<u-row customStyle="margin:10px">
			<u-col span="12">
				<u-button class="custom-style" @click="handel_edit_click" type="success" size="small">编辑
				</u-button>
			</u-col>
		</u-row>
		<u-row customStyle="margin:10px">
			<u-col span="12">
				<u-button class="custom-style" @click="handel_delete_click" :disabled="disabled_Delete" type="error"
					size="small">删除
				</u-button>
			</u-col>
		</u-row>
		<u-modal :show="show" :showCancelButton="true" :content='content' @confirm="handle_confirmDelete_click"
			@cancel="handle_confirmCancel_click"></u-modal>
	</view>
</template>

<script>
	import {
		transformPostBody,
		transformRequestURL
	} from "@/utils/requestParams.js";
	import {
		QueryDeviceInstallList,
		addDeviceInstall,
		updateDeviceInstall,
		getDeviceInstall,
		delDeviceInstall,
		QueryDeviceInstallHistory
	} from "@/api/elder/DeviceInstall.js";

	export default {
		data() {
			return {
				show: false, //删除确认窗口
				content: '确认删除此条设备信息?',

				detailform: {
					deviceName: '', //设备名称
					deviceNum: '', //设备编码
					deviceType: '', //设备属性
					isGateway: '', //是否网关设备
					gatewayNum: '', //所属网关编码
					manufacturer: '', //生产厂商

					name: '', //老人姓名
					sex: '', //性别
					idNumber: '', //身份证号码
					phone: '', //联系电话
					province: '',
					city: '',
					district: '',
					town: '',
					village: '',
					street: '',
					roomNum: '', //房屋号
					residenceAdd: '', //详细地址

					emergencyContactName: '', //紧急联系人
					emergencyContactPhone: '', //紧急联系人电话

					institutionName: '', //所属养老机构
					institutionCode: '', //机构社会信用代码

					deployName: '', //部署人员
					registerName: '', //登记人员
					auditorName: '', //审核人员
					deviceDeploy: '', //入户时间
					notes: '' //备注
				},
				loading: false, //加载中
				id: null,
			}
		},
		onLoad: function(options) {
			console.log('options', options.id)
			this.id = options.id
		},
		onShow() {
			this.getList();
		},
		computed: {
			disabled_Delete() {
				// return !this.$auth.hasRole("admin")
				return false
			},
			getAddress() {
				return function(item) {
					let result = "";
					if (item.city) result += item.city
					if (item.district) result += item.district
					if (item.town) result += item.town
					if (item.village) result += item.village
					if (item.street) result += item.street
					return result
				}
			},
			getDetailAddress() {
				return function(item) {
					let result = "";
					if (item.roomNum) result += item.roomNum
					if (item.residenceAdd) result += item.residenceAdd
					return result
				}
			},

		},
		methods: {
			getList() {
				this.loading = true;
				getDeviceInstall(this.id).then((response) => {
					this.loading = false;
					console.log("getDeviceInstall", response);
					this.detailform = Object.assign({}, this.detailform, response.data)
				});
			},
			handel_edit_click() {
				this.$tab.navigateTo('/pages/DeviceInstall/edit?id=' + this.id)
			},
			//删除设备信息
			handel_delete_click() {
				this.show = true;
			},
			handle_confirmDelete_click() {
				this.loading = true;
				delDeviceInstall([this.id]).then((response) => {
					uni.$u.toast('删除成功')
					this.loading = false;
					console.log("delDeviceInstall", response);
					this.show = false;
					this.$tab.navigateBack();
				}).catch(errors => {
					console.log("errors", errors, this.id);
					uni.$u.toast('删除失败')
				});
			},
			handle_confirmCancel_click() {
				this.show = false;
			}

		},
	}
</script>

<style lang="scss">
	page {
		background-color: white;
		display: flex;
		justify-content: center;
	}

	.page-content {
		width: 93%;
	}

	.custom-style {
		width: 80%;
		font-weight: bolder;
		font-size: 17px;
	}
</style>